package com.mobi.Survey.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mobi.Survey.map.Category;
import com.mobi.Survey.map.R;

public class CustomAdapterCategories extends BaseAdapter {

	private List<Category> categories;
	private LayoutInflater mInflater;

	public CustomAdapterCategories(Context ctx, List<Category> categories) {
		this.mInflater = LayoutInflater.from(ctx);
		this.categories = categories;
	}

	public void setData(List<Category> categories){
		this.categories = categories;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return categories.size();
	}

	@Override
	public Category getItem(int position) {
	 
		return categories.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	static final class ViewHolder {

		TextView txtCategory;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {

		final Category category = categories.get(position);
		final ViewHolder holder;
		if (convertView == null) {

			convertView = mInflater.inflate(R.layout.row_categories, null);

			holder = new ViewHolder();

			holder.txtCategory = (TextView) convertView.findViewById(R.id.txtCategory);

			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();

		}

		
		
		holder.txtCategory.setText(category.getName());

		return convertView;

	}
}
